/*
 *  Planet.cpp
 *  GLRender
 *
 *  Created by Patrick zulian on 5/26/10.
 *  Copyright 2010 University  of Lugano. All rights reserved.
 *
 */

#include "Planet.h"
#include "Physics.h"
#include "SoundEngine.h"

Planet::Planet(const Point3d &position, const double mass , const double radius )
: WMovingObject(position, Point3d(0,0,0), mass, radius)
{
	setLife(2000.0);
	setStrength(300.0);
	reaction.addReaction("SpaceShip",HARM);
	reaction.addReaction("Projectile",DIE);
	reaction.addReaction("Asteroid",HARM);
}

void
Planet::renderOn(AbstractRenderer *renderer) {
	glPushMatrix();
	renderer->defaultTransform(this);
	renderer->render(this);
	glPopMatrix();
}

void 
Planet::onCollision (WObject *from)
{
	switch (from->getReaction().getReaction("Asteroid")) {
		case HARM:
			Physics::getInstance()->collide(this, from);
			collided = true;
			this->life -= from->getStrength();
			if (this->life <= 0) {
				this->alive() = false;
				SoundEngine::getInstance()->play("Explosion");
			}
			break;
		case DIE:
			this->alive() = false;
			SoundEngine::getInstance()->play("Explosion");
			break;
		default:
			Physics::getInstance()->collide(this, from);
			collided = true;
			break;
	}
}